package com.hzeport.bgs22emduty.util;

import com.hzeport.bgs22emduty.entity.BasePersonInfo;

import java.math.BigInteger;
import java.util.Comparator;

public class PersonCompareUtil {


    public static Comparator<BasePersonInfo> comparePersonForSort(){

        return (a,b)->{
            String aGlobalSort=a.getGlobalSort().replaceAll("[^0-9]","");
            String bGlobalSort=b.getGlobalSort().replaceAll("[^0-9]","");
            int aLength=a.getGlobalSort().length();
            int bLength=b.getGlobalSort().length();
            if (aLength!=bLength){
                int minLength=aLength;
                if (minLength>bLength){
                    minLength=bLength;
                }
                BigInteger bigIntegerA=new BigInteger(aGlobalSort.substring(0,minLength));
                BigInteger bigIntegeB=new BigInteger(bGlobalSort.substring(0,minLength));
                return bigIntegerA.compareTo(bigIntegeB);
            }else {
                BigInteger bigIntegerA=new BigInteger(aGlobalSort);
                BigInteger bigIntegeB=new BigInteger(bGlobalSort);
                return bigIntegerA.compareTo(bigIntegeB);
            }
        };
    }

}
